package com.kt.mes.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.kt.mes.domain.WasteStore;
import com.kt.mes.service.IWasteStoreService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 废料库Controller
 * 
 * @author lzc
 * @date 2021-04-19
 */
@RestController
@RequestMapping("/mes/WasteStore")
public class WasteStoreController extends BaseController
{
    @Autowired
    private IWasteStoreService wasteStoreService;

    /**
     * 查询废料库列表
     */
    @PreAuthorize("@ss.hasPermi('mes:WasteStore:list')")
    @GetMapping("/list")
    public TableDataInfo list(WasteStore wasteStore)
    {
        startPage();
        List<WasteStore> list = wasteStoreService.selectWasteStoreList(wasteStore);
        return getDataTable(list);
    }

    /**
     * 导出废料库列表
     */
    @PreAuthorize("@ss.hasPermi('mes:WasteStore:export')")
    @Log(title = "废料库", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WasteStore wasteStore)
    {
        List<WasteStore> list = wasteStoreService.selectWasteStoreList(wasteStore);
        ExcelUtil<WasteStore> util = new ExcelUtil<WasteStore>(WasteStore.class);
        return util.exportExcel(list, "WasteStore");
    }

    /**
     * 获取废料库详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:WasteStore:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wasteStoreService.selectWasteStoreById(id));
    }

    /**
     * 新增废料库
     */
    @PreAuthorize("@ss.hasPermi('mes:WasteStore:add')")
    @Log(title = "废料库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WasteStore wasteStore)
    {
        return toAjax(wasteStoreService.insertWasteStore(wasteStore));
    }

    /**
     * 修改废料库
     */
    @PreAuthorize("@ss.hasPermi('mes:WasteStore:edit')")
    @Log(title = "废料库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WasteStore wasteStore)
    {
        return toAjax(wasteStoreService.updateWasteStore(wasteStore));
    }

    /**
     * 删除废料库
     */
    @PreAuthorize("@ss.hasPermi('mes:WasteStore:remove')")
    @Log(title = "废料库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wasteStoreService.deleteWasteStoreByIds(ids));
    }
}
